package main

import (
	"bytes"
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
)

func main() {
	/*resp, err := http.Get("http://example.com/")
	if err != nil {
		return
	}
	defer resp.Body.Close()
	io.Copy(os.Stdout,resp.Body)
	*/

	byte, e := ioutil.ReadFile("/Users/zhuxiao/Downloads/两仪式.jpg")
	if e != nil {
		return
	}

	resp, err := http.Post("http://example.com/upload", "image/jpeg", bytes.NewReader(byte))
	if err != nil {
		return
	}

	resp, err = http.PostForm("http://example.com/posts", url.Values{"title": {"article title"}, "content": {"article body"}})
	if err != nil {
		return
	}

	resp, err = http.Head("http://example.com")
	if err != nil {
		return
	}

	//高阶封装
	//1,自定义http.client
	client := &http.Client{}
	resp, err = client.Get("http://example.com")

	//······
	req, err := http.NewRequest("GET", "http://example.com", nil)
	req.Header.Add("User-Agent", "Our Custom User-Agent")
	req.Header.Add("If-None-Match", `W/"TheFileEtag"`)

	resp, err = client.Do(req)

	//自定义http.Transport
	/*	tr:=&http.Transport{
			TLSClientConfig:&tls.Config{RootCAs:pool},
			DisableCompression:true,
		}
		client=&http.Client{Transport:tr}
		resp,err=client.Get("")*/

	if err != nil {
		return
	}

	defer resp.Body.Close()
	io.Copy(os.Stdout, resp.Body)
}
